package com.vibrationkeyboard.app.model

import org.junit.Test
import org.junit.Assert.*
import kotlin.math.sqrt

class SensorDataTest {

    @Test
    fun testMagnitude() {
        val sensorData = SensorData(3f, 4f, 0f)
        assertEquals(5f, sensorData.magnitude, 0.001f)
    }

    @Test
    fun testNormalized() {
        val sensorData = SensorData(3f, 4f, 0f)
        val normalized = sensorData.normalized
        assertEquals(1f, normalized.magnitude, 0.001f)
    }

    @Test
    fun testAddition() {
        val data1 = SensorData(1f, 2f, 3f)
        val data2 = SensorData(4f, 5f, 6f)
        val result = data1 + data2
        assertEquals(SensorData(5f, 7f, 9f), result)
    }

    @Test
    fun testSubtraction() {
        val data1 = SensorData(5f, 7f, 9f)
        val data2 = SensorData(1f, 2f, 3f)
        val result = data1 - data2
        assertEquals(SensorData(4f, 5f, 6f), result)
    }

    @Test
    fun testMultiplication() {
        val data = SensorData(1f, 2f, 3f)
        val result = data * 2f
        assertEquals(SensorData(2f, 4f, 6f), result)
    }

    @Test
    fun testDistance() {
        val data1 = SensorData(0f, 0f, 0f)
        val data2 = SensorData(3f, 4f, 0f)
        assertEquals(5f, data1.distance(data2), 0.001f)
    }

    @Test
    fun testDotProduct() {
        val data1 = SensorData(1f, 2f, 3f)
        val data2 = SensorData(4f, 5f, 6f)
        assertEquals(32f, data1.dot(data2), 0.001f)
    }

    @Test
    fun testCrossProduct() {
        val data1 = SensorData(1f, 0f, 0f)
        val data2 = SensorData(0f, 1f, 0f)
        val result = data1.cross(data2)
        assertEquals(SensorData(0f, 0f, 1f), result)
    }

    @Test
    fun testFromArray() {
        val array = floatArrayOf(1f, 2f, 3f)
        val result = SensorData.fromArray(array)
        assertEquals(SensorData(1f, 2f, 3f), result)
    }

    @Test
    fun testZero() {
        val zero = SensorData.zero()
        assertEquals(SensorData(0f, 0f, 0f), zero)
    }
} 